package com.cn.por.util.ClassLoader;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * 类加载器ClassLoader
 * @see 参考 https://blog.csdn.net/xyang81/article/details/7292380
 * 1、什么是ClassLoader? 
 * 	简单来说
 * 2、使用spring boot devtools 框架实现热加载
 * @see 参考 https://blog.csdn.net/weixin_33816946/article/details/91932151
 * @author 26983
 * 
 */
public class ClassLoaderUtil {

	/**
	 * 查看启动类加载器BootStrapClassLoader，加载了哪些内容。
	 * 输出内容如下：
	 * 	file:/D:/Program%20Files/Java/jdk1.8.0_181/jre/lib/resources.jar
	 	file:/D:/Program%20Files/Java/jdk1.8.0_181/jre/lib/rt.jar
		file:/D:/Program%20Files/Java/jdk1.8.0_181/jre/lib/sunrsasign.jar
		file:/D:/Program%20Files/Java/jdk1.8.0_181/jre/lib/jsse.jar
		file:/D:/Program%20Files/Java/jdk1.8.0_181/jre/lib/jce.jar
		file:/D:/Program%20Files/Java/jdk1.8.0_181/jre/lib/charsets.jar
		file:/D:/Program%20Files/Java/jdk1.8.0_181/jre/lib/jfr.jar
		file:/D:/Program%20Files/Java/jdk1.8.0_181/jre/classes
		可以看出，该加载器主要是加载了jdk下相关的jar包
	 */
	public static void bootStrapClassLoader() {
		URL[] urls = sun.misc.Launcher.getBootstrapClassPath().getURLs();
		for(int i=0; i<urls.length; i++) {
			System.out.println(urls[i].toExternalForm());
		}
		//或者通过如下方式获取
		System.out.println(System.getProperty("sun.boot.class.path"));
		
	}

	/**
	 * 扩展类加载器extensionClassLoader,主要加载java的扩展类库，默认加载JAVA_HOME/jre/lib/ext/
	 * 目录下的所有jar。
	 * 
	 */
	public static void extensionClassLoader() {
		System.out.println(System.getProperty("java.ext.dirs"));
	}
	
	/**
	 * 系统类加载器，负责加载应用程序classpath目录下所有jar、class、xml等文件。
	 */
	public static void appClassLoader() {
		ClassLoader appClassLoader = ClassLoaderUtil.class.getClassLoader();
		URL url = appClassLoader.getResource("com/cn/por/util/ClassLoader/ClassLoaderUtil.class");
		System.out.println(url);
	}
	
	
	
	
	
	public static void main(String[] args) {
		//bootStrapClassLoader();
		//extensionClassLoader();
		//appClassLoader();
		Map<String,String> a = new HashMap<String,String>();
		System.out.println(a instanceof Map);
	}
}
